<?php


/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

use Illuminate\Support\Facades\Route;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

Route::group(['as'=>'v1.','prefix'=>'v1','namespace'=>'App\\Api\\Controllers\\v1'],function (){
    Route::any('notify/{type}', 'CommonController@notify')->name('notify');
    Route::post('oauth/wechatLogin', 'OauthController@wechatLogin')->name('oauth.wechatLogin');
    Route::get('code/{order_no}/', function ($order_no){
        $cacheKey = "codeUrl".$order_no;
        $res = Cache::get($cacheKey);
        if (!$res){
            $res = QrCode::encoding('UTF-8')->size(200)->generate($order_no);
            Cache::put($cacheKey,$res);
        }
        return response($res)->header("content-type","image/svg+xml");
    })->name('code');
    Route::group(['as'=>'common.','prefix'=>'common'],function (){
        Route::get('config', 'CommonController@config')->name('config');
        Route::get('index', 'CommonController@index')->name('index');
        Route::get('article', 'CommonController@article')->name('article');
        Route::get('brands', 'CommonController@brands')->name('brands');
        Route::get('typeColor', 'CommonController@typeColor')->name('typeColor');
        Route::get('serviceCategory', 'CommonController@serviceCategory')->name('serviceCategory');
        Route::get('services', 'CommonController@services')->name('services');
        Route::get('getService', 'CommonController@getService')->name('getService');
        Route::get('moneys', 'CommonController@moneys')->name('moneys');

        Route::get('businessCategory', 'CommonController@businessCategory')->name('businessCategory');
        Route::get('businessList', 'CommonController@businessList')->name('businessList');
//        Route::get('business/{id}', 'CommonController@business')->name('business');

        Route::get('shop/{id}', 'CommonController@shop')->name('shop');
        Route::get('getShops', 'CommonController@getShops')->name('getShops');
        Route::get('workers', 'CommonController@workers')->name('workers');
        Route::get('joinText', 'CommonController@joinText')->name('joinText');
    });
    Route::group(['as'=>'goods.','prefix'=>'goods'],function (){
        Route::get('index', 'GoodsController@index')->name('index');
        Route::get('list', 'GoodsController@list')->name('list');
        Route::get('detail', 'GoodsController@detail')->name('detail');
        Route::get('courier_fee', 'GoodsController@courier_fee')->name('courier_fee');
    });

    Route::group(['as'=>'card.','prefix'=>'card'],function (){
        Route::get('index', 'CardController@index')->name('index');
        Route::get('detail/{id}', 'CardController@detail')->name('detail');
    });
    Route::post('appoint/servicePrice', 'AppointController@servicePrice')->name('servicePrice');
    Route::group(['middleware' => ['auth:sanctum']],function (){
        Route::group(['as'=>'oauth.','prefix'=>'oauth'],function (){
            Route::post('saveInfo', 'OauthController@saveInfo')->name('saveInfo');
            Route::post('mobile', 'OauthController@mobile')->name('mobile');
        });

        Route::group(['as'=>'goods.','prefix'=>'goods'],function (){
            Route::post('pay', 'GoodsController@pay')->name('pay');
        });

        Route::group(['as'=>'common.','prefix'=>'common'],function (){
            Route::post('upload', 'CommonController@upload')->name('upload');
        });

        Route::group(['as'=>'order.','prefix'=>'order'],function (){
            Route::get('list', 'OrderController@list')->name('list');
            Route::get('detail/{order_no}', 'OrderController@detail')->name('detail');
            Route::post('confirm/{order_no}', 'OrderController@confirm')->name('confirm');
            Route::post('refund/{order_no}', 'OrderController@refund')->name('refund');
            Route::post('scan/{order_no}', 'OrderController@scan')->name('scan');
        });

        //预约洗车
        Route::group(['as'=>'appoint.','prefix'=>'appoint'],function (){
            Route::post('payService', 'AppointController@payService')->name('payService');
            Route::get('orders', 'AppointController@orders')->name('orders');
            Route::get('orderStatusNum', 'AppointController@orderStatusNum')->name('orderStatusNum');
            Route::get('detail/{order_id}', 'AppointController@detail')->name('detail');
            Route::post('cancel/{order_id}', 'AppointController@cancel')->name('cancel');
            Route::post('arrive', 'AppointController@arrive')->name('arrive');
            Route::post('confirm', 'AppointController@confirm')->name('confirm');
            Route::get('snatchOrders', 'AppointController@snatchOrders')->name('snatchOrders');
            Route::post('receive/{order_id}', 'AppointController@receive')->name('receive');
            Route::post('finish/{order_id}', 'AppointController@finish')->name('finish');
        });

        Route::group(['as'=>'coupon.','prefix'=>'coupon'],function (){
            Route::get('index', 'CouponController@index')->name('index');
            Route::post('receive/{id}', 'CouponController@receive')->name('receive');
            Route::get('list', 'CouponController@list')->name('list');
            Route::get('allows', 'CouponController@allows')->name('allows');
        });

        Route::group(['as'=>'card.','prefix'=>'card'],function (){
            Route::get('list', 'CardController@list')->name('list');
            Route::get('getDetail/{id}', 'CardController@getDetail')->name('getDetail');
            Route::get('allows', 'CardController@allows')->name('allows');
            Route::post('pay', 'CardController@pay')->name('pay');
        });

        Route::group(['as'=>'user.','prefix'=>'user'],function (){
            Route::get('/', 'UserController@index')->name('user');
            //海报
            Route::get('poster', 'UserController@poster')->name('poster');
            //添加与修改车牌号
            Route::get('cars', 'UserController@cars')->name('cars');
            Route::post('saveCar', 'UserController@saveCar')->name('saveCar');
            Route::post('deleteCar/{id}', 'UserController@deleteCar')->name('deleteCar');
            Route::post('saveDefaultCar/{id}', 'UserController@saveDefaultCar')->name('saveDefaultCar');

            //地址接口
            Route::get('address', 'UserController@address')->name('address');
            Route::post('saveAddress', 'UserController@saveAddress')->name('saveAddress');
            Route::post('delAddress/{id}', 'UserController@delAddress')->name('delAddress');
            Route::post('saveDefaultAddress/{id}', 'UserController@saveDefaultAddress')->name('saveDefaultAddress');

            //充值
            Route::post('payMoney', 'UserController@payMoney')->name('payMoney');
            Route::get('moneyLogs', 'UserController@moneyLogs')->name('moneyLogs');
            //评价
            Route::post('apprise', 'UserController@apprise')->name('apprise');


            //收藏与取消收藏
            Route::post('collect/{id}', 'UserController@collect')->name('collect');
            Route::get('collects', 'UserController@collects')->name('collects');
            Route::get('visits', 'UserController@visits')->name('visits');

            //添加与修改,银行卡列表
            Route::get('banks', 'UserController@banks')->name('banks');
            Route::post('saveBank', 'UserController@saveBank')->name('saveBank');
            Route::post('deleteBank/{id}', 'UserController@deleteBank')->name('deleteBank');

            Route::get('child', 'UserController@child')->name('child');

        });

        Route::group(['as'=>'manager.','prefix'=>'manager'],function (){
            Route::get('agent', 'ManagerController@agent')->name('agent');
            Route::get('shop', 'ManagerController@shop')->name('shop');
            Route::get('worker', 'ManagerController@worker')->name('worker');
            Route::get('services', 'ManagerController@services')->name('services');
            Route::get('goods', 'ManagerController@goods')->name('goods');
            Route::get('expends', 'ManagerController@expends')->name('expends');
            Route::post('cash', 'ManagerController@cash')->name('cash');
            Route::get('cashLogs', 'ManagerController@cashLogs')->name('cashLogs');
            Route::get('ranks', 'ManagerController@ranks')->name('ranks');
        });
    });
});
